package com.gxm.base.grammar_运算语法.stream;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class Demo2 {
    public static void main(String[] args) throws ParseException {
        List<Date> dates = new ArrayList<>();
        DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = df.parse("2019-12-02");
        Date date2 = df.parse("2019-12-01");
        Date date3 = df.parse("2019-12-04");
        Date date4 = df.parse("2019-12-03");
        Date date5 = df.parse("2019-12-05");
        dates.add(date1);
        dates.add(date2);
        dates.add(date3);
        dates.add(date4);
        dates.add(date5);
        //倒序
        //List<Date> datesSort = dates.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        //正序
        List<Date> datesSort = dates.stream().sorted().collect(Collectors.toList());
        System.out.println(datesSort.toString());
    }
}
